autocmd!
mapclear
mapclear!
noremap / 
noremap! / 
noremap `` /
noremap! `` /
nnoremap K <nop>
nnoremap o o<esc>
nnoremap O O<esc>
set ignorecase smartcase incsearch backspace=2 linebreak hidden autoindent tabstop=4 history=150 showbreak=\ 

let g:loaded_matchparen=1
cd /sdcard-ext/vimhome
so abbrev
autocmd VimEnter * if argc() == 0 | normal `C | endif
autocmd VimLeavePre * normal mC

let LABELS = ["a","b","c",
\"d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s",
\"t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I",
\"J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y",
\"Z","1","2","3","4","5","6","7","8","9","0"]
function! JumpTo(range)
	normal! Hmt
	for i in range(0,a:range)
		exe 'normal! Wr' . g:LABELS[i%len(g:LABELS)]
	endfor
	normal! 'tzt
	echo "Jump to?"
	redraw
	let label=nr2char(getchar())
	let offset=getchar()
	let offset=(49 <= offset && offset <= 57) ? offset-48 : 1
	normal! u'tzt
	let index=index(g:LABELS,label)
	if index!=-1
		exe 'normal! ' . ((offset-1)*len(g:LABELS)+index+1) . 'W'
	endif
endfu
nnoremap <TAB> :call JumpTo(248)<CR>

function! CapWait(prev)
	redraw
	let input = nr2char(getchar())
	if input=~'[.?!\r\n[:blank:]]'
		exe 'normal! i' . input . "\<Right>"
		return CapWait(input)
	else
		if input=~'[\e\/]' 
			return "\<del>"
		elseif a:prev=~'[\r\n[:blank:]]'
			return toupper(input) . "\<del>"
		else 
			return input . "\<del>"
		endif
	endif
endfu

function! CapHere()
	let trunc = getline(".")[0:col(".")-2] 
	return col(".")==1 ? CapWait("\r") :
	\	trunc=~'[?!.]\s*$\|^\s*$' ? CapWait(trunc[-1:-1]) :
	\	"\<del>"
endfu
imap . ._<Left><C-R>=CapWait('.')<CR>
imap ? ?_<Left><C-R>=CapWait('?')<CR>
imap ! !_<Left><C-R>=CapWait('!')<CR>
imap <CR> <CR>_<Left><C-R>=CapWait("\r")<CR>
imap <NL> <NL>_<Left><C-R>=CapWait("\n")<CR>
nmap a a_<Left><C-R>=CapHere()<CR>
nmap A A_<Left><C-R>=CapHere()<CR>
nmap i i_<Left><C-R>=CapHere()<CR>
nmap I I_<Left><C-R>=CapHere()<CR>
